package com.czr.dao.service.impl;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czr.dao.entity.CzrColumn;
import com.czr.dao.entity.CzrLandscape;
import com.czr.dao.mapper.CzrColumnMapper;
import com.czr.dao.mapper.CzrLandscapeMapper;
import com.czr.dao.service.CzrColumnService;
import com.czr.dao.service.CzrLandscapeService;
import com.czr.util.TencentCosUtil;
import com.czr.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 栏目表 服务实现类
 * </p>
 *
 */
@Service
public class CzrLandscapeServiceImpl extends ServiceImpl<CzrLandscapeMapper, CzrLandscape> implements CzrLandscapeService {

    @Autowired
    public CzrColumnMapper czrColumnMapper;

    @Override
    public Result<Object> dictionary() throws Exception {
        TencentCosUtil tencentCosUtil=new TencentCosUtil();
        List<CzrLandscape> czrLandscapes=this.list();
        for (CzrLandscape czrLandscape:czrLandscapes){
            czrLandscape.setImage(tencentCosUtil.imgFile_wx(czrLandscape.getImage()));
        }
        return Result.data(200,czrLandscapes,null);
    }

    @Override
    public Result<Object> updateLandscape(String param)  {
        //解析
        if(StringUtils.isEmpty(param)){
            return null;
        }
        try {
            JSONArray array=JSONArray.parseArray(param);
            for (Object obj:array){
                JSONObject object=JSONObject.parseObject(obj.toString());
                CzrLandscape czrLandscape=new CzrLandscape();
                czrLandscape.setId(object.getLong("id"));
                czrLandscape.setName(object.getString("name"));
                czrLandscape.setImage(object.getString("image"));
                czrLandscape.setSynopsis(object.getString("synopsis"));
                czrLandscape.setCAbstract(object.getString("cabstract"));
                czrLandscape.updateById();
            }
        }catch (Exception e){
            e.printStackTrace();
            return Result.success(200, "修改失败！");
        }


       return Result.success(200, "修改成功！");
    }
}
